package com.xiaobaibai.common.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseFormat<T> {

    private int code;

    private String msg;

    private T data;


    private ResponseFormat(int code,String msg,T data){
        this.code=code;
        this.msg=msg;
        this.data=data;
    }

    private ResponseFormat(int code,String msg){
        this.code=code;
        this.msg=msg;
    }

    public static<T> ResponseFormat<T> createSuccessResponse(String msg,T data){
        return new ResponseFormat<T>(ResponseCode.SUCCESS.getCode(),msg,data);
    }

    public static<T> ResponseFormat<T> createSuccessResponseOnlyMessage(String msg){
        return new ResponseFormat<T>(ResponseCode.SUCCESS.getCode(),msg);
    }

    public static<T> ResponseFormat<T> createFailureResponseOnlyMsg(ResponseCode code,String msg){
        return new ResponseFormat<T>(code.getCode(),msg);
    }


}
